package fr.unice.polytech.chord.core;

import org.objectweb.proactive.ActiveObjectCreationException;
import org.objectweb.proactive.api.PAActiveObject;
import org.objectweb.proactive.core.node.Node;
import org.objectweb.proactive.core.node.NodeException;

/**
 * Factory for {@link ChordNode}.
 * 
 * @author Anthony Parisy
 * @author Laurent Pellegrino
 * @author Marc Valdener
 * 
 * @version 10/28/2009
 */
public class ChordFactory {

	/**
	 * Creates a new ChordNode ActiveObject.
	 * 
	 * @return the new Tracker object created.
	 * @throws ActiveObjectCreationException
	 * @throws NodeException
	 */
	public static ChordNode newActiveChordNode()
			throws ActiveObjectCreationException, NodeException {
		return ChordFactory.newActiveChordNode(null, null);
	}

	/**
	 * Creates a new ChordNode ActiveObject.
	 * 
	 * @param id
	 *            the identifier associated to the Chord node.
	 * @return the new Tracker object created.
	 * @throws ActiveObjectCreationException
	 * @throws NodeException
	 */
	public static ChordNode newActiveChordNode(Integer id)
			throws ActiveObjectCreationException, NodeException {
		return ChordFactory.newActiveChordNode(id, null);
	}

	/**
	 * Creates a new ChordNode ActiveObject.
	 * 
	 * @param id
	 *            the identifier associated to the Chord node.
	 * @param node
	 *            the node to use for deployment.
	 * @return the new Tracker object created.
	 * @throws ActiveObjectCreationException
	 * @throws NodeException
	 */
	public static ChordNode newActiveChordNode(Integer id, Node node)
			throws ActiveObjectCreationException, NodeException {
		return (ChordNode) PAActiveObject.newActive(ChordNode.class.getName(),
				new Object[] { id }, node);
	}

	/**
	 * Creates a new Tracker ActiveObject.
	 * 
	 * @return the new Tracker object created.
	 * @throws ActiveObjectCreationException
	 * @throws NodeException
	 */
	public static Tracker newActiveTracker()
			throws ActiveObjectCreationException, NodeException {
		return ChordFactory.newActiveTracker(null);
	}

	/**
	 * Creates a new Tracker ActiveObject.
	 * 
	 * @param node
	 *            the node to use for deployment.
	 * @return the new Tracker object created.
	 * @throws ActiveObjectCreationException
	 * @throws NodeException
	 */
	public static Tracker newActiveTracker(Node node)
			throws ActiveObjectCreationException, NodeException {
		return (Tracker) PAActiveObject.newActive(Tracker.class.getName(),
				new Object[] {}, node);
	}

}
